package cn.stylefeng.guns.modular.demos.constant.factory;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import cn.stylefeng.guns.modular.demos.entity.BizUploadFile;
import cn.stylefeng.guns.modular.demos.mapper.BizPassCheckRequestDynamicMapper;
import cn.stylefeng.guns.modular.demos.mapper.BizPassCheckRequestMapper;
import cn.stylefeng.guns.modular.demos.mapper.BizUploadFileMapper;
import cn.stylefeng.guns.modular.demos.model.params.BizPassCheckRequestDynamicParam;
import cn.stylefeng.guns.modular.demos.model.result.BizPassCheckRequestDynamicResult;
import cn.stylefeng.roses.core.util.SpringContextHolder;
import cn.stylefeng.roses.core.util.ToolUtil;


/**
 * 快捷查询方法
 *
 * @author zjj
 * @date 2019年5月27日 下午12:44:21
 */
@Component
@DependsOn("springContextHolder")
public class BconstantFactory implements IBconstantFactory {

	private BizPassCheckRequestMapper bizPassCheckRequestMapper = SpringContextHolder.getBean(BizPassCheckRequestMapper.class);
		
	private BizPassCheckRequestDynamicMapper bizPassCheckRequestDynamicMapper = SpringContextHolder.getBean(BizPassCheckRequestDynamicMapper.class);
	
	private BizUploadFileMapper bizUploadFileMapper = SpringContextHolder.getBean(BizUploadFileMapper.class);
	
    public static IBconstantFactory me() {
        return SpringContextHolder.getBean("bconstantFactory");
    }
	   
	@Override
	public List<BizPassCheckRequestDynamicResult> BizPassCheckRequestDynamicList(Long reqId) {
		// TODO Auto-generated method stub
		BizPassCheckRequestDynamicParam param = new BizPassCheckRequestDynamicParam ();
		param.setPassCheckRequestId(reqId);
		return bizPassCheckRequestDynamicMapper.customList2(param);
	}
	
	@Override
	public BizUploadFile getBizUploadFile(Long id)
	{
		return bizUploadFileMapper.selectById(id);
	}
	
	
	//1、object转换成map
	@Override
	public Map<String,Object> Obj2Map(Object obj) throws Exception{
		Map<String,Object> map=new HashMap<String, Object>();
		Field[] fields = obj.getClass().getDeclaredFields();
		for(Field field:fields){
			field.setAccessible(true);
			map.put(field.getName(), field.get(obj));
		}
		return map;
	}

	//2、map转换为object
//	@Override
//	public Object map2Obj(Map<String,Object> map,Class<?> clz) throws Exception{
//		Object obj = clz.newInstance();
//		Field[] declaredFields = obj.getClass().getDeclaredFields();
//		for(Field field:declaredFields){
//			int mod = field.getModifiers();
//			if(Modifier.isStatic(mod) || Modifier.isFinal(mod)){
//				continue;
//			}
//			field.setAccessible(true);
//			field.set(obj, map.get(field.getName()));
//		}
//		
//		return obj;
//　　}
	
	
}
